<template>
  <div>
    <div class="pds-tip">
      <el-form :inline="true" :model="pageData.params" class="filter">
        <el-form-item>
          <el-input v-model="pageData.params.plmArticleNo" placeholder="请输入机型全码" clearable></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="search(pageData.params)">查询</el-button>
          <el-button type="danger" @click="reset">重置</el-button>
          <el-button type="success" @click="centerDialogVisible = true">发起成本查询</el-button>
        </el-form-item>
      </el-form>
    </div>
    <el-table :data="tableData" border style=" margin: 15px auto;">
      <el-table-column width="50" align="center" label="序号">
        <template
          slot-scope="scope"
        >{{(pageData.params.page-1)*pageData.params.size+(scope.$index+1)}}</template>
      </el-table-column>
      <el-table-column prop="createTime" label="申请日期" align="center" width="200px"></el-table-column>
      <el-table-column prop="oaId" label="流程ID" align="center"></el-table-column>
      <el-table-column width="130px" align="center" label="是否授权">
        <template slot-scope="scope">
          <span v-if="scope.row.auth===0">否</span>
          <span v-if="scope.row.auth===1">是</span>
        </template>
      </el-table-column>
      <el-table-column prop="createUserName" label="创建人" align="center" width="110px"></el-table-column>
      <el-table-column width="130px" align="center" label="状态">
        <template slot-scope="scope">
          <span v-if="scope.row.status===0">等待</span>
          <span v-if="scope.row.status===1">查询中</span>
          <span v-if="scope.row.status===2">查询成功</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" width="220px">
        <template slot-scope="scope">
          <el-button type="success" @click="showDetail(scope.row.id)" size="small">查看明细</el-button>
        </template>
      </el-table-column>
    </el-table>
    <pagination :pageData="pageData.params" @pageChange="changePage" @changeSize="changeSize"></pagination>
    <!-- 弹框 -->
    <el-dialog :title="dialogTitle" :visible.sync="centerDialogVisible" width="25%" center>
      <el-form :inline="true" class="filter">
        <el-form-item label="机型全码:">
          <el-input v-model="editForm.plmArticleNos" placeholder="请输入内容" width="150px"></el-input>
        </el-form-item>
        <el-form-item label="要求完成时间:">
          <el-date-picker value-format="yyyy-MM-dd" v-model="editForm.completeDate" type="date" placeholder="选择日期"></el-date-picker>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="centerDialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="submitEdit()">查 询</el-button>
      </span>
    </el-dialog>
    <!-- 弹框 -->
    <el-dialog :title="dialogTitle" :visible.sync="DetailDialogVisible" width="75%" center>
      <el-table :data="tableData2" border style=" margin: 15px auto;">
        <el-table-column prop="plmArticleNo" label="机型全码" align="center" width="150px"></el-table-column>
        <el-table-column prop="plmModelNo" label="型号" align="center"></el-table-column>
        <el-table-column prop="name" label="产品名称" align="center"></el-table-column>
        <el-table-column prop="productCategoryName" label="产品小类" align="center"></el-table-column>
      </el-table>
      <span slot="footer" class="dialog-footer">
        <el-button @click="DetailDialogVisible = false">取 消</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import * as api from "@/api/product/cost/index";

export default {
  name: "requireGraphic",
  data() {
    return {
      centerDialogVisible: false,
      DialogVisible: false,
      DetailDialogVisible: false,
      editForm: {},
      dialogTitle: "",
      customerList: [],
      pageData: {
        params: {
          page: 1,
          size: 10,
          plmArticleNo: "",
          title: "",
          total: ""
        },
        list: []
      },
      tabName: "first",
      tableData: [],
      tableData2: []
    };
  },
  created() {
    this.getList();
  },
  activated() {
    this.getList();
  },
  methods: {
    getList() {
      const params = this.pageData.params;
      api.getOAQueryList(params).then(response => {
        if (response.code === 200) {
          this.tableData = response.data.rows;
          this.pageData.params.total = response.data.total;
          // console.log(this.pageData.params)
        }
      });
    },
    // 编辑/添加>提交按钮
    submitEdit() {
      api.getQueryFullCost(this.editForm).then(res => {
        this.getList();
        if (res.code === 200) {
          this.$message({
            message: this.dialogTitle + "成功!",
            type: "success"
          });
          this.centerDialogVisible = false;
          this.getList();
          return false;
        }
        this.$message({
          type: "error",
          message: res.message
        });
      });
    },
    search() {
      this.pageData.params.page = 1;
      this.getList();
    },
    changePage(pageData) {
      this.pageData.params.page = pageData.page;
      this.getList();
    },
    changeSize(pageSize) {
      this.pageData.params.size = pageSize;
      this.pageData.params.page = 1;
      this.getList();
    },
    reset() {
      this.pageData.params = {
        page: 1,
        size: 10,
        applyNo: "",
        plmModelNo: "",
        title: "",
        customerName: "",
        customerArray: []
      };
      this.getList();
    },
    //查看明细
    showDetail(costAuthId) {
      if (costAuthId) {
        this.dialogTitle = "查看明细";
        this.tableData2 = [];
        this.DetailDialogVisible = true;
        api.getRequestDetails({ costAuthId }).then(response => {
          if (response.code === 200) {
            console.log(response.data);
            this.tableData2 = response.data.rows;
          }
        });
      }
    }
  }
};
</script>
<style rel="stylesheet/scss" lang="scss" scoped>
.bigbox {
  width: 100%;
  background: #f5f5f5;
  overflow: hidden;
}
.pds-tip-green .filter {
  padding-top: 29px !important;
}
.el-header,
.el-footer {
  width: 300px;
  background-color: #ffffff;
  color: #333;
  text-align: center;
  line-height: 60px;
  border: 1px solid #ccc;
}

.el-aside {
  background-color: #d3dce6;
  color: #333;
  text-align: center;
  line-height: 200px;
}

.el-main {
  width: 300px;
  background-color: #fff;
  color: #333;
  text-align: center;
  line-height: 160px;
  margin-bottom: 30px;
  border: 1px solid #ccc;
}

body > .el-container {
  margin-bottom: 40px;
}

.el-container:nth-child(5) .el-aside,
.el-container:nth-child(6) .el-aside {
  line-height: 260px;
}

.el-container:nth-child(7) .el-aside {
  line-height: 320px;
}

.custom-tree-node {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 14px;
  padding-right: 8px;
}

.el-tabs__header {
  margin: 0;
}

.pds-tip-green {
  padding: 8px 16px;
  background-color: #f8f8f8;
  border-radius: 4px;
  border-left: 5px solid #42b983;
  margin: 0 0 20px;
  p {
    font-size: 14px;
    color: #5e6d82;
    line-height: 1.5em;
    margin-top: 5px;
    margin-bottom: 5px;
  }
}
</style>

